﻿#region Imports
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
#endregion

namespace CheckerWPF.Utils
{
    public static class Utilities
    {
        #region Declarations
        public const ContentAlignment left = ContentAlignment.MiddleLeft;
        public const ContentAlignment right = ContentAlignment.MiddleRight;
        #endregion

        #region Methods
        public static bool IsBoolean(object value)
        {
            bool res = false;
            return Boolean.TryParse(System.Convert.ToString(value), out res);
        }

        public static bool IsContentAlignment(object value)
        {
            try
            {
                ContentAlignment align = (ContentAlignment)value;
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static ContentAlignment GetOnlyLR(ContentAlignment align, ContentAlignment defaultAlign)
        {
            if (defaultAlign != left && defaultAlign != right) defaultAlign = right; // method default
            ContentAlignment? finalAlign = null;

            if (IsContentAlignment(align))
            {
                switch (align)
                {
                    case ContentAlignment.BottomLeft:
                    case ContentAlignment.MiddleLeft:
                    case ContentAlignment.TopLeft:
                        finalAlign = left;
                        break;

                    case ContentAlignment.BottomRight:
                    case ContentAlignment.MiddleRight:
                    case ContentAlignment.TopRight:
                        finalAlign = right;
                        break;

                    default:
                        finalAlign = defaultAlign;
                        break;
                }
            }

            return finalAlign.Value;
        }
        #endregion
    }
}
